home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Sapphire Collection / Software Vault (Sapphire Collection) (Digital Impact).ISO / cdr47 / trace122.zip / TRACE12.ASM < prev    next >
Assembly Source File  |  1997-02-13  |  13KB  |  368 lines

  1.             page    60,132
  2.             title   "TRACE - Interrupt Tracer"
  3.             ;make sure this gets linked last
  4.             page
  5. code        segment para public 'code'
  6.             assume  cs:code,ds:code,es:code
  7.  
  8.             public  trace_table,init
  9.  
  10.             extrn   trace_begin:word,trace_curr:word,trace_end:word,trace_bytes:word
  11.  
  12.             extrn   feed:near,crlf:near,print_hex:near,print_line:near
  13.             extrn   disp_active:near,selvideo:near,periscope:near
  14.  
  15.             extrn   hndlr_index:word,ict_index:word,prt_base:word
  16.             extrn   our_cs:word,test_cs:word,old_int_5:dword
  17.  
  18.             extrn   prtsc:near
  19.  
  20. radix       dw      10
  21. one_k       dw      1024
  22.  
  23.             include b:trace1e.aic
  24.  
  25. trace_table db     0
  26.  
  27. asciitable  db    '0123456789ABCDEF' ;table of characters 
  28.  
  29. asciibin    proc  near                 ;si - source of characters (left end)
  30.                                        ;ax - contents in binary
  31.                                        ;cx - length in bytes
  32.             push  bx
  33.             xor   ax,ax 
  34.             xor   bx,bx 
  35. asciiloop:
  36.             mov   bl,[si]          ;get character pointed to by SI
  37.             cmp   bl,' '           ;is character a blank?
  38.             je    asciiexit        ;if so, that is it.
  39.             cmp   bl,'0'
  40.             jl    asciierror
  41.             mul   radix            ;multiply ax by radix
  42.             cmp   bl,'9'
  43.             jg    asciihex         ;if character > 9 must be hex
  44.             and   bl,0fh           ;pick up numeric part
  45. asciiadd:                            ;add to accumulator
  46.             add   ax,bx
  47.             inc   si               ;scan right
  48.             loop  asciiloop
  49.             jmp   asciiexit
  50.  
  51. asciihex:   cmp   radix,10         ;radix >10?
  52.             jle   asciierror       ;if not, error
  53.             or    bl,20h           ;make lower case 
  54.             cmp   bl,'a'
  55.             jl    asciierror
  56.             cmp   bl,'f'
  57.             jg    asciierror
  58.             sub   bl,87            ;turn 'A' into 10, etc
  59.             jmp   asciiadd
  60.  
  61. asciierror:                        ;error exit
  62.             xor   ax,ax            ;return a zero on error
  63.             stc                    ;set carry flag: error
  64.             jmp   asciiret         ;exit
  65.  
  66. asciiexit:                         ;non-error exit
  67.             clc
  68. asciiret:                          ;general exit
  69.             pop   bx
  70.             ret
  71. asciibin    endp
  72.  
  73. parmlen     equ        80h
  74. parmdata    equ        81h
  75.  
  76. scan_parm   proc       near                   ;get next parm start in es:di
  77.             push       ax
  78.             mov        al,' '                 ;put blank in accumulator
  79.             cmp        cx,0                   ;is there any parm left?
  80.             je         scan_none              ;if not, just exit
  81.  
  82. scan_loop:  repz       scasb                  ;get byte pointed to by  es:di
  83.             je         scan_none              ;if all blank, no parm`
  84.             dec        di                     ;back up over character
  85.             inc        cx
  86.             clc                               ;set no carry
  87. scan_ret:      
  88.             pop        ax                     ;restore register
  89.             ret
  90. scan_none:    
  91.             stc                               ;set carry
  92.             jmp        scan_ret
  93.  
  94. scan_parm   endp
  95.  
  96.  
  97.  
  98. ;********************************************************
  99. ;
  100. ; Startup messages (lost once we're resident)
  101. ;
  102. ;********************************************************
  103.  
  104. copyright       db      cr,lf
  105.                 db      "TRACE - Interrupt Tracer version 1.21 01/26/87"
  106.                 db      cr,lf
  107.                 db      cr,lf
  108.                 db      "Written by Joan Riff for:"
  109.                 db      cr,lf
  110.                 db      "Computerwise Consulting Services P.O. Box 813, McLean VA 22101  (703) 280-2809"
  111.                 db      cr,lf
  112.                 db      "Modified 01/26/87 A. B. Krueger - ARNY KRUEGER @ EXEC-PC"
  113.                 db      cr,lf,"$"
  114.  
  115. default_msg     db      cr,lf
  116.                 db      "Using default sized trace table." 
  117.                 db      cr,lf 
  118.                 db      "Usage is: TRACE  [parameter]"
  119.                 db      cr,lf
  120.                 db      "Optional parameter is size in K between 10 and 53"
  121.                 db      cr,lf,"$"
  122.  
  123. here_already    db      cr,lf
  124.                 db      "TRACE already installed, errorlevel = 10"
  125.                 db      cr,lf,"$"
  126.  
  127. intro_msg       db      cr,lf
  128.                 db      cr,lf
  129.                 db      "Trace is now resident."
  130.                 db      cr,lf
  131.                 db      "Use '/U 9' Periscope command"
  132.  
  133.                 if      prt_scr
  134.                 db      " (or SHIFT-PrtSc)"
  135.                 endif
  136.  
  137.                 db      " for access."
  138.                 db      cr,lf
  139.                 db      "When you run Periscope, include command-line arg /I:$"
  140. bad_exit        db      "has a bad Exit field. ICT deactivated.$"
  141. two_prtscrs     db      "overlays SHIFT-PrtSc. ICT deactivated.$"
  142. no_printer      db      cr,lf,"*** Warning: LPT1 not available$"
  143. err_msg         db      cr,lf,"*** ICT #"
  144. err_ict         db      "0 $"
  145. final_msg       db      cr,lf
  146.                 db      cr,lf,"Final ICT's:",cr,lf,"$"
  147.  
  148.  
  149.  
  150.         subttl  Startup (init) code
  151.         page
  152.  
  153. ;********************************************************
  154. ;
  155. ; Startup code, which installs us in memory and sets up interrupts
  156. ; to be handled.
  157. ;
  158. ;********************************************************
  159.  
  160. init:
  161.         mov     bx,0                    ;set up to see if i am already here
  162.         mov     ax,iamhere
  163.         int     21h                     ;run the test
  164.         cmp     bx,iamhere              ;if AX and BX swapped, i am here already
  165.         jne     init00
  166.  
  167.         mov     dx,offset here_already  ;complaint department
  168.         mov     ah,9
  169.         int     21h
  170.         mov     al,10                   ;error level = 10
  171.         mov     ax,4ch
  172.         int     21h                     ;return to caller
  173.  
  174. init00:
  175.         mov     ax,trace_size           ;set default trace table size
  176.         mov     di,parmdata
  177.         xor     cx,cx
  178.         mov     cl,cs:[parmlen]
  179.         call    scan_parm               ;call scan for start of parm
  180.         jc      init01                  ;if none, use default
  181.  
  182.         mov     si,di                   ;now loading, not scanning
  183.         call    asciibin                ;turn chars into binary in ax
  184.         jc      init01                  ;any errors? - use default
  185.  
  186.         cmp     ax,53                   ;above 53K?
  187.         ja      init01                  ;then set default
  188.  
  189.         cmp     ax,9                    ;too small?
  190.         ja      init02                  ;if not use it
  191.  
  192. init01:
  193.         mov     dx,offset default_msg
  194.         mov     ah,9
  195.         int     021h
  196.         mov     ax,trace_size           ;set default trace table size
  197. init02:
  198.         mul     one_k                   ;turn number into K-bytes
  199.         mov     trace_bytes,ax
  200.  
  201.         mov     our_cs,cs               ;save for handlers' use
  202.         mov     test_cs,cs              ;start normalized CS for testing
  203.         mov     ax,offset init          ;include all of resident part in it
  204.         mov     cl,4
  205.         shr     ax,cl
  206.         add     test_cs,ax              ;done normalizing it
  207.         mov     dx,offset copyright
  208.         mov     ah,9
  209.         int     021h
  210.  
  211. ;
  212. ; Get printer base I/O address for use later
  213. ;
  214.  
  215.         mov     ax,040h                 ;point to parallel table at 0040:0008
  216.         mov     es,ax
  217.         mov     dx,es:[8]               ;get LPT1's base address
  218.         mov     prt_base,dx             ;save it
  219.         or      dx,dx                   ;is there an LPT1?
  220.         jnz     init2                   ;yes, move on
  221.         mov     dx,offset no_printer    ;no, give warning message...
  222.         call    selvideo                ;...after switching to video
  223.         call    print_line
  224.  
  225. init2:
  226.  
  227. ;
  228. ; Init proper I/O mode
  229. ;
  230.  
  231.         if      use_prt
  232.         call    selprint
  233.         else
  234.         call    selvideo
  235.         endif
  236.  
  237. ;
  238. ; Install Periscope access interrupt # 'peri_int'
  239. ;
  240.  
  241.         mov     al,peri_int             ;INT # being installed
  242.         mov     ah,025h                 ;DOS "Install Int Vector" func
  243.         mov     dx,offset periscope     ;DS:DX = handler for this INT
  244.         int     021h
  245.  
  246. ;
  247. ; Install SHIFT-PrtSc interrupt
  248. ;
  249.  
  250.         mov     ax,3505h                ;get old int5 handler in es:bx
  251.         int     021h
  252.         mov     word ptr [old_int_5],bx
  253.         mov     word ptr [old_int_5+2],es
  254.  
  255.         if      prt_scr
  256.  
  257.         mov     ax,2505h                ;DOS "Install Int Vector" func
  258.         mov     dx,offset PrtSc         ;DS:DX = handler for this INT
  259.         int     021h
  260.         endif
  261.         
  262. ;
  263. ; Install interrupt vectors for any active ICT's
  264. ;
  265.  
  266.         mov     cx,number_icts          ;number of ICT's
  267.         xor     si,si                   ;Start with ICT # 0
  268.  
  269. init5:
  270.         mov     bx,ict_index[si]        ;get pointer to an ICT
  271.         mov     al,[bx].ICT_flags       ;get flags to AL
  272.         test    al,F_ACTIVE             ;is this ICT active?
  273.         jz      init10                  ;no, move on to next one
  274.  
  275. ; ------- Validate type of interrupt exit
  276.  
  277.         and     al,F_RET+F_RET2+F_IRET
  278.         cmp     al,F_RET
  279.         jz      init6                   ;this one's legal
  280.         cmp     al,F_RET2
  281.         jz      init6                   ;this one's legal
  282.         cmp     al,F_IRET
  283.         jz      init6                   ;this one's legal
  284.         mov     dx,offset bad_exit      ;bad field, give error message
  285.  
  286. init5b:
  287.  
  288. ;
  289. ; Print error message at DS:DX and mark ICT de-activated
  290. ;
  291.  
  292.         push    dx                      ;save error message text
  293.         mov     ax,si                   ;get ICT # for error message
  294.         shr     ax,1
  295.         and     al,7                    ;(just in case)
  296.         or      al,'0'                  ;make into ASCII digit
  297.         mov     err_ict,al              ;move into error header
  298.         mov     dx,offset err_msg       ;print error header first
  299.         call    print_line
  300.         pop     dx                      ;recover error message itself
  301.         call    print_line              ;display it
  302.         xor     [bx].ICT_flags,F_ACTIVE ;de-activate this ICT
  303.         jmp     short init10            ;goto next ICT
  304.  
  305. init6:
  306.         mov     al,[bx].ICT_intnum      ;get int number to AL
  307.  
  308.         if      prt_scr
  309.         cmp     al,5                    ;trying to trace INT 5?
  310.         jnz     init6b                  ;no, it's all right
  311.         mov     dx,offset two_prtscrs   ;yes, give error message
  312.         jmp     init5b
  313.  
  314. init6b:
  315.         endif
  316.  
  317.         mov     ah,035h                 ;get current vector for this INT
  318.         push    bx                      ;(save ICT pointer!!!)
  319.         int     021h
  320.         mov     dx,bx                   ;put vector's offset somewhere safe
  321.         pop     bx                      ;(restore ICT pointer!!!)
  322.  
  323.         mov     word ptr [bx].ICT_orig_hndlr,dx
  324.         mov     word ptr [bx].ICT_orig_hndlr+2,es
  325.  
  326.         mov     dx,hndlr_index[si]      ;DS:DX = new vector for this INT
  327.         mov     ah,025h                 ;tell DOS to install it
  328.         int     021h                    ;(intnum still in AL)
  329.  
  330.         mov     dx,offset trace_table   ;minimum end of program
  331.         mov     trace_curr,dx           ;reset current trace table entry
  332.  
  333. init10:
  334.         add     si,2                    ;up to next ICT
  335.         loop    init5                   ;till done all ICT's
  336.  
  337. ;
  338. ; List final ICT's
  339. ;
  340.  
  341.         mov     dx,offset final_msg
  342.         call    print_line
  343.         call    disp_active             ;display all active ICT's
  344.         call    crlf
  345.  
  346. ;
  347. ; Terminate and stay resident
  348. ;
  349.  
  350.         mov     dx,offset intro_msg     ;give him intro message
  351.         call    print_line
  352.         mov     al,peri_int
  353.         call    print_hex
  354.         call    crlf
  355.         call    feed                    ;extra CRLF's for printer
  356.  
  357.         mov     dx,offset trace_table   ;minimum end of program
  358.         mov     trace_begin,dx          ;set trace table start
  359.         mov     trace_curr,dx           ;reset current trace table entry
  360.         add     dx,trace_bytes          ;add in length of trace table
  361.         mov     trace_end,dx            ;save offset of end of trace table
  362.         int     027h
  363.  
  364. code        ends
  365.             end  
  366.  
  367.  
  368.